# lib/stair_master/concerns/traverser.rb
##
##
##
module StairMaster
  module Concerns
    module Traversal
      extend ActiveSupport::Concern

      included do
        helper_method :current_step,
                      :current_step_name,
                      :current_step_index,
                      :next_step,
                      :next_step_index,
                      :next_step_name,
                      :previous_step,
                      :previous_step_index,
                      :previous_step_name
      end

      def first_step
        @stair_master_first_step ||= get_step_by_name available_steps.first
      end

      def last_step
        @stair_master_last_step ||= get_step_by_name available_steps.last
      end

      ## Current Step -------------------------------------
      def current_step_index
        @stair_master_current_step_index ||= get_step_index_by_name current_step_name
      end

      def current_step
        @stair_master_current_step ||= get_step_by_index current_step_index
      end

      def current_step_name
        @stair_master_current_step_name ||= controller_name.to_sym
      end

      ## Next Step ----------------------------------------
      def next_step_index
        @stair_master_next_step_index ||= get_next_step_index
      end

      def next_step
        @stair_master_next_step ||= ( next_step_index.nil? ? nil : get_step_by_index(next_step_index) )
      end

      def next_step_name
        @stair_master_next_step_name ||= ( next_step_index.nil? ? nil : get_step_name_by_index(next_step_index) )
      end

      ## Previous Step ------------------------------------
      def previous_step_index
        @stair_master_previous_step_index ||= get_previous_step_index
      end

      def previous_step
        @stair_master_previous_step ||= ( previous_step_index.nil? ? nil : get_step_by_index(previous_step_index) )
      end

      def previous_step_name
        @stair_master_previous_step_name ||= ( previous_step_index.nil? ? nil : get_step_name_by_index(previous_step_index) )
      end
    end
  end
end